package com.example.ncov_management_system.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class WebInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("url:{}",request.getRequestURI());
        String name = (String) request.getSession().getAttribute("name");
        if (name == null) {
            response.sendRedirect("/toLogin");
            return false;
        } else {
            return true;
        }
    }
}
